<form class="layui-form layui-box modal-form-box" enctype="multipart/form-data"  data-auto="true" id="myform" method="post">
    <div class="layui-form-item">

        <div class="layui-form-item">
            <label class="layui-form-label">上传csv文件</label>
            <div class="layui-input-block">
                <input type="file" id="uploadfile" name="uploadfile"  accept=".csv" class="layui-input">
            </div>
        </div>

        <div class="hr-line-dashed"></div>

        <div class="layui-form-item text-center">
            <button class="layui-btn" id="submit" type='submit'>上传数据</button>
            <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
        </div>

</form>

<script>
 $("#myform").submit(function (e) {
     $.ajax({
         url: '/miniprograms/cart/upload',
         type: 'POST',
         cache: false,
         data: new FormData($('#myform')[0]),
         processData: false,
         contentType: false
     }).done(function(res) {
        var res = JSON.parse(res);
        layer.msg(res.msg);
        window.setTimeout(function (args) {
            layer.closeAll();
            window.location.href="/admin.html#/miniprograms/cart/index";
        }, 2000);
     }).fail(function(res) {

     });

     return false;
 });
</script>
